# M Orsi, 7 oct 09
# script to unwrap com xy coordinates of permeant from z-constraint simulation
# usage:  python /home/orsi/brahmsProject/analysisCode/zConstraint/unwrapXYcoords.py 

L = 6.3 # [nm], average box edge length along the x and y direction

inFile = open( 'xySolute.dat', 'r' )
outFile = open( 'xySoluteUnwrapped.dat', 'w' )

x = []; y = []   # lists 

for line in inFile:            # scan through file lines
    xval, yval = line.split()  
    x.append(float(xval)); y.append(float(yval)) # store values in x and y arrays

for i in range(len(x)-1):
    if abs(x[i+1]-x[i]) > L / 2: # PBC was applied, need to unwrap!
        if x[i] > 0: 
            x[i+1] = x[i+1] + L
        else:
            x[i+1] = x[i+1] - L
    if abs(y[i+1]-y[i]) > L / 2: # PBC was applied, need to unwrap!
        if y[i] > 0: 
            y[i+1] = y[i+1] + L
        else:
            y[i+1] = y[i+1] - L
          
for i in range(len(x)):
    outFile.write('% 5.4f % 5.4f \n' % (x[i], y[i]))
    
        
